Dashboard

Row

confirmed

595,677,066

active

589,224,297 (98.9%)

recovered

0 (0%)

death

6,452,769 (1.1%)

Row

Confirmed Cases

Active Cases

Recovered Cases

Death Cases

Map

Map

Region-wise

Column

Locations of people killed by COVID-19

Column

Visualisation

Column

Daily New Cases - China vs. Rest of the World

Key Data & Plots

Row {data-width = 400}

Cases Status Update for 2022-08-20

Recovery and Death Rates by Country

Row {data-width = 400}

Daily Cumulative Cases by Type

New Cases - Top 15 Countries (2022-08-20)

Cumulative Results

Column

Cumulative Confirmed Cases

Cumulative Active Cases

Row

Cumulative Recovered Cases

Cumulative Death Cases

India

Column

Confirmed Cases in India

Column

confirmed

44,339,429

active

43,812,097 (98.8%)

recovered

0 (0%)

death

527,332 (1.2%)

US

Column

Confirmed Cases in US

Column

confirmed

93,634,408

active

92,593,267 (98.9%)

recovered

0 (0%)

death

1,041,141 (1.1%)

UK

Column

Confirmed Cases in UK

Column

confirmed

23,675,485

active

23,487,754 (99.2%)

recovered

0 (0%)

death

187,731 (0.8%)

About

The Coronavirus Dashboard

This Coronavirus dashboard provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic. This dashboard is built with R using the Rmarkdown using flexdashboard framework and can easily reproduce by others.

Data

The input data for this dashboard is the coronavirus R package. The data and dashboard is refreshed on a daily bases. The raw data pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository

Packages

Deployment and reproducibility

The dashboard can be deployed to Rpubs or to Github docs. If you wish to deploy and/or modify the dashboard on your Github account, you can apply the following steps:

For any question or feedback, you can either open an issue or contact me on LinkedIn.

Contributions

Special thanks John Ng and Zhan Liang Chan for guiding me through hosting this work on Github.io, and to all package developers who have contributed their bit in this development

Dedication

This dashboard has been created for usage by epidemiologists, data scientists and public in general. It is dedicated to all the health workers across the globe who are fighting this war from the front and impacting millions of lives with their great work. God bless them all.

This too shall pass!

---
title: "Coronavirus Dashboard"
author: ""
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
    vertical_layout: fill
    theme: cerulean
---


```{r setup, include = F}

# Downloading data from Github Repository

download.file("https://github.com/RamiKrispin/coronavirus/raw/master/data/coronavirus.rda", destfile = "cvirus")
load("cvirus")

coronavirus$type[coronavirus$type == "recovery"] <- "recovered"

# Calling packages
suppressPackageStartupMessages(c(library(flexdashboard),
library(shinythemes),
library(coronavirus),
library(covid19italy),
library(tidyverse),
library(plotly),
library(maps),
library(leaflet),
library(leafpop),
library(purrr),
library(echarts4r),
library(knitr),
library(DT)))


# COLORS:

# A list of colors is available at the following link - http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf

# Defining color palette - also used for value box colors
confirmed_color <- "gray"
active_color <- "gold"
recovered_color <- "#6cc71c"
death_color <- "#f52525"


# Creating Datasets :-

# confirmed/active/recovered/death cases by country - old version

df <- coronavirus %>% 
  group_by(country, type) %>%
  summarise(total = sum(cases)) %>%
  pivot_wider(names_from =  type, 
                     values_from = total) %>%
  mutate(unrecovered = confirmed - ifelse(is.na(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
  arrange(-confirmed) %>%
  ungroup() %>%
  mutate(country = if_else(country == "United Arab Emirates", "UAE", country)) %>%
  mutate(country = if_else(country == "Mainland China", "China", country)) %>%
  mutate(country = if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
  mutate(country = if_else(country == "Iran (Islamic Republic of)", "Iran", country)) %>%
  mutate(country = if_else(country == "Republic of Korea", "South Korea", country)) %>%
  mutate(country = if_else(country == "Russian Federation", "Russia", country)) %>%
  mutate(country = if_else(country == "Korea, South", "South Korea", country)) %>%
  mutate(country = if_else(country == "Dominican Repolic", "Dominican", country)) %>%
  mutate(country = trimws(country)) %>%
  mutate(country = factor(country)) %>%
  mutate(country = factor(country, levels = unique(country)))


# India specific dataset
df_india <- df %>%
  filter(country == "India")

# US specific dataset
df_us <- df %>%
  filter(country == "US")

# UK specific dataset
df_uk <- df %>%
  filter(country == "United Kingdom")

# Cumulative Cases :-
df_daily <- coronavirus %>% 
  dplyr::group_by(date, type) %>%
  dplyr::summarise(total = sum(cases, na.rm = T)) %>%
  tidyr::pivot_wider(names_from = type,
                     values_from = total) %>%
  dplyr::arrange(date) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(active =  confirmed - death - recovered) %>%
  dplyr::mutate(confirmed_cumulative = cumsum(confirmed),
         active_cumulative = cumsum(active),
         recovered_cumulative = cumsum(recovered),
         death_cumulative = cumsum(death))

df1 <- coronavirus %>% 
  filter(date == max(date))

#------------ Trajectory plot data prep ------------

df_china <- coronavirus %>% 
  dplyr::filter(type == "confirmed", country == "China") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(china = cumsum(cases)) %>%
  dplyr::filter(china > 100)  %>%
  dplyr::select(-cases, -date)

df_china$index <- 1:nrow(df_china)


df_ind <- coronavirus %>% 
  dplyr::filter(type == "confirmed", country == "India") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(india = cumsum(cases)) %>%
  dplyr::filter(india > 100)  %>%
  dplyr::select(-cases, -date)

df_ind$index <- 1:nrow(df_ind)


df_pakistan <- coronavirus %>% 
  dplyr::filter(type == "confirmed", country == "Pakistan") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(pakistan = cumsum(cases)) %>%
  dplyr::filter(pakistan > 100)  %>%
  dplyr::select(-cases, -date)

df_pakistan$index <- 1:nrow(df_pakistan)


df_russia <- coronavirus %>% 
  dplyr::filter(type == "confirmed", country == "Russia") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(russia = cumsum(cases)) %>%
  dplyr::filter(russia > 100)  %>%
  dplyr::select(-cases, -date)

df_russia$index <- 1:nrow(df_russia)


df_canada <- coronavirus %>% 
  dplyr::filter(type == "confirmed", country == "Canada") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(canada = cumsum(cases)) %>%
  dplyr::filter(canada > 100)  %>%
  dplyr::select(-cases, -date)

df_canada$index <- 1:nrow(df_canada)


df_australia <- coronavirus %>% 
  dplyr::filter(type == "confirmed", country == "Australia") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(australia = cumsum(cases)) %>%
  dplyr::filter(australia > 100)  %>%
  dplyr::select(-cases, -date)

df_australia$index <- 1:nrow(df_australia)


df_unitedkingdom <- coronavirus %>% 
  dplyr::filter(type == "confirmed", country == "United Kingdom") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(unitedkingdom = cumsum(cases)) %>%
  dplyr::filter(unitedkingdom > 100)  %>%
  dplyr::select(-cases, -date)

df_unitedkingdom$index <- 1:nrow(df_unitedkingdom)


df_france <- coronavirus %>% dplyr::filter(type == "confirmed", country == "France") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(france = cumsum(cases)) %>%
  dplyr::filter(france > 100)  %>%
  dplyr::select(-cases, -date)

df_france$index <- 1:nrow(df_france)

df_unitedstates <- coronavirus %>% 
  dplyr::filter(type == "confirmed", country == "US") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(unitedstates = cumsum(cases)) %>%
  dplyr::filter(unitedstates > 100)  %>%
  dplyr::select(-cases, -date)

df_unitedstates$index <- 1:nrow(df_unitedstates)

df_iran <- coronavirus %>% 
  dplyr::filter(type == "confirmed", country == "Iran") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(iran = cumsum(cases)) %>%
  dplyr::filter(iran > 100)  %>%
  dplyr::select(-cases, -date)

df_iran$index <- 1:nrow(df_iran)

df_sk <- coronavirus %>% dplyr::filter(type == "confirmed", country == "Korea, South") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(sk = cumsum(cases)) %>%
  dplyr::filter(sk > 100)  %>%
  dplyr::select(-cases, -date)

df_sk$index <- 1:nrow(df_sk)

df_spain <- coronavirus %>% dplyr::filter(type == "confirmed", country == "Spain") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(spain = cumsum(cases)) %>%
  dplyr::filter(spain > 100)  %>%
  dplyr::select(-cases, -date)

df_spain$index <- 1:nrow(df_spain)


df_italy <- italy_total %>% dplyr::select(date, italy = cumulative_cases) %>%
  dplyr::filter(italy > 100) %>%
  dplyr::select(-date)

df_italy$index <- 1:nrow(df_italy)

df_trajectory <- df_china %>% 
  dplyr::left_join(df_ind, by = "index") %>%
  dplyr::left_join(df_pakistan, by = "index") %>%
  dplyr::left_join(df_australia, by = "index") %>%
  dplyr::left_join(df_canada, by = "index") %>%
  dplyr::left_join(df_russia, by = "index") %>%
  dplyr::left_join(df_italy, by = "index") %>%
  dplyr::left_join(df_iran, by = "index") %>%
  dplyr::left_join(df_sk, by = "index") %>%
  dplyr::left_join(df_unitedstates, by = "index") %>%
  dplyr::left_join(df_france, by = "index") %>%
  dplyr::left_join(df_unitedkingdom, by = "index") %>%
  dplyr::left_join(df_spain, by = "index")


# Recoding Country names per their common names
df_map <- df %>%
  dplyr::mutate(country = recode_factor(country,
                                 `US` = "United States",
                                 `UK` = "United Kingdom",
                                 `UAE` = "United Arab Emirates",
                                 `South Korea` = "Korea"))

```



Dashboard
=======================================================================

Row
-----------------------------------------------------------------------

### confirmed {.value-box}

```{r}

valueBox(value = paste(format(sum(df$confirmed), big.mark = ","), "", sep = " "), 
         caption = "Total Confirmed Cases", 
         icon = "fas fa-user-md",
         color = confirmed_color)
```


### active {.value-box}

```{r}

valueBox(value = paste(format(sum(df$unrecovered, na.rm = T), big.mark = ","),
                       " (", round(100 * sum(df$unrecovered, na.rm = T) / sum(df$confirmed), 1),
                       "%)", sep = ""),
         caption = "Active Cases",
         icon = "fas fa-ambulance",
         color = active_color)
```

### recovered {.value-box}

```{r}

valueBox(value = paste(format(sum(df$recovered, na.rm = T), big.mark = ","),
                       " (", round(100 * sum(df$recovered, na.rm = T) / sum(df$confirmed), 1),
                       "%)", sep = ""),
         caption = "Recovered Cases",
         icon = "fas fa-heartbeat",
         color = recovered_color)
```

### death {.value-box}

```{r}

valueBox(value = paste(format(sum(df$death, na.rm = T), big.mark = ","), 
                       " (", round(100 * sum(df$death, na.rm = T) / sum(df$confirmed), 1), 
                       "%)", sep = ""),
         caption = "Death Cases", 
         icon = "fas fa-bed",
         color = death_color)

```


Row {.tabset .tabset-fade}
-----------------------------------------------------------------------

### Confirmed Cases

```{r}

df_map %>%
  e_charts(country) %>%
  e_map(confirmed) %>%
  e_title("Confirmed Cases by Country", left = "center") %>%
  e_visual_map() %>%
  e_theme("infographic") %>%
  e_visual_map_range(selected = list(0,200))
  

```

### Active Cases

```{r}

df_map %>%
  e_charts(country) %>%
  e_map(unrecovered) %>%
  e_title("Active Cases by Country", left = "center") %>%
  e_visual_map() %>%
  e_theme("infographic") %>%
  e_visual_map_range(selected = list(0,200))


```

### Recovered Cases

```{r}

df_map %>%
  e_charts(country) %>%
  e_map(recovered) %>%
  e_title("Recovered Cases by Country", left = "center") %>%
  e_visual_map() %>%
  e_theme("infographic") %>%
  e_visual_map_range(selected = list(0,200))


```

### Death Cases 

```{r}

df_map %>%
  e_charts(country) %>%
  e_map(death) %>%
  e_title("Death Cases by Country", left = "center") %>%
  e_visual_map() %>%
  e_theme("infographic") %>%
  e_visual_map_range(selected = list(0,200))
  

```



Map
=======================================================================

**Map**

```{r map}

cv_data_for_plot <- coronavirus %>%
  dplyr::filter(cases > 0) %>%
  dplyr::group_by(country, province, lat, long, type) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::mutate(log_cases = 2 * log(cases)) %>%
  dplyr::ungroup()

cv_data_for_plot.split <- cv_data_for_plot %>%
  split(cv_data_for_plot$type)

pal <- colorFactor(c(active_color, death_color, recovered_color), domain = c("confirmed", "death", "recovered"))

map_object <- leaflet() %>% addProviderTiles(providers$Stamen.Toner)
names(cv_data_for_plot.split) %>%
  purrr::walk(function(df) {
    map_object <<- map_object %>%
      addCircleMarkers(data = cv_data_for_plot.split[[df]],
                 lng = ~long, lat = ~lat,
                 color = ~pal(type),
                 stroke = F,
                 fillOpacity = 0.8,
                 radius = ~log_cases,
                 popup =  popupTable(cv_data_for_plot.split[[df]],
                                              feature.id = F,
                                              row.numbers = F,
                                              zcol = c("type", "cases", "country", "province")),
                 group = df,
                 labelOptions = labelOptions(noHide = F,
                                             direction = 'auto'))
  })

map_object %>%
  addLayersControl(
    overlayGroups = names(cv_data_for_plot.split),
    options = layersControlOptions(collapsed = F)
  )

```



Region-wise
=======================================================================

Column 
-------------------------------------
    
### 
    
```{r}

df_table <- df %>%
  select(country, confirmed, death)

df_table %>%
  datatable(rownames = F)

```
   
   
### Locations of people killed by COVID-19

```{r, fig.width = 10, fig.height = 7}

world_map <- map_data("world")


coronavirus_maps <- coronavirus %>%
  filter(coronavirus$type == "death")

world_map %>%
  ggplot() +
  geom_polygon(aes(x = long, y = lat, group = group),
               fill = "gray",
               color = "gold") +
  geom_point(data = coronavirus_maps, 
             aes(x = coronavirus_maps$long,
             y = coronavirus_maps$lat,
             color = death_color,
             alpha = 0.7,
             size = 1.2)) +
  theme_classic() + 
  theme(
    axis.line = element_blank(),
    axis.text = element_blank(),
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    legend.position = "none"
  ) 

```
   
Column
-------------------------------------
   
### 

```{r}

plotly::plot_ly(data = df,
                x = ~ country,
                y = ~ confirmed,
                type = "bar",
                name = "Confirmed",
                marker = list(color = active_color)) %>%
  plotly::add_trace(y = ~ recovered,
                    name = "Recovered",
                    marker = list(color = recovered_color)) %>%
  plotly::add_trace(y = ~ death,
                    name = "Death",
                    marker = list(color = death_color)) %>%
  plotly::layout(barmode = 'stack',
                 yaxis = list(title = "Total Cases (log)",
                              type = "log"),
                 xaxis = list(title = "", tickangle = 30),
                 hovermode = "compare")

```
 
 
 
Visualisation
=======================================================================

Column
------------------------------------- 

### Daily New Cases - China vs. Rest of the World
    
```{r}

daily_confirmed <- coronavirus %>%
  dplyr::filter(type == "confirmed") %>%
  dplyr::mutate(country = dplyr::if_else(country == "India", 
                                         "India", if_else(country == "US", 
                                                          "US", if_else(country == "Italy", 
                                                                        "Italy", if_else(country == "Spain", 
                                                                                         "Spain", if_else(country == "China", 
                                                                                                          "China", "Rest of the World")))))) %>%
  dplyr::group_by(date, country) %>%
  dplyr::summarise(total = sum(cases)) %>% 
  dplyr::ungroup() %>%
  tidyr::pivot_wider(names_from = country, values_from = total) 


# Plotting the data

daily_confirmed %>%
  plotly::plot_ly() %>% 
  plotly::add_trace(x = ~ date, 
                    y = ~ India, 
                    type = "scatter", 
                    mode = "lines+markers",
                    name = "India") %>% 
  plotly::add_trace(x = ~ date, 
                    y = ~ US, 
                    type = "scatter", 
                    mode = "lines+markers",
                    name = "US") %>% 
  plotly::add_trace(x = ~ date, 
                    y = ~ Italy, 
                    type = "scatter", 
                    mode = "lines+markers",
                    name = "Italy") %>% 
  plotly::add_trace(x = ~ date, 
                    y = ~ Spain, 
                    type = "scatter", 
                    mode = "lines+markers",
                    name = "Spain") %>% 
  plotly::add_trace(x = ~ date, 
                    y = ~ China, 
                    type = "scatter", 
                    mode = "lines+markers",
                    name = "China") %>% 
  plotly::add_trace(x = ~ date, 
                    y = ~ `Rest of the World`, 
                    type = "scatter", 
                    mode = "lines+markers",
                    name = "Rest of the World") %>% 
  plotly::add_annotations(x = as.Date("2020-02-13"),
                          y = 15133,
                          text = paste("        One time adjustment -", 
                                       "", 
                                       "China modified the diagnostic criteria"),
                          xref = "x",
                          yref = "y",
                          arrowhead = 5,
                          arrowhead = 3,
                          arrowsize = 1,
                          showarrow = TRUE,
                          ax = 40,
                          ay = -40) %>%
  plotly::add_annotations(x = as.Date("2020-02-26"),
                          y = 577,
                          text = paste("New cases outside of China surpass the ones inside China"),
                          xref = "x",
                          yref = "y",
                          arrowhead = 5,
                          arrowhead = 3,
                          arrowsize = 1,
                          showarrow = TRUE,
                          ax = 40,
                          ay = -60) %>%
  plotly::layout(title = "",
                 legend = list(x = 0.1, y = 0.9),
                 yaxis = list(title = "Number of New Cases"),
                 xaxis = list(title = "Date"),
                 hovermode = "compare",
                 margin =  list(b = 10,
                                t = 10,
                                pad = 2))

```



Trends
=======================================================================

Column
------------------------------------- 

### Recovery and Death Rates for Countries with at Least 25k confirmed cases

```{r}

coronavirus %>% 
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total_cases = sum(cases)) %>%
  tidyr::pivot_wider(names_from = type, values_from = total_cases) %>%
  dplyr::arrange(-confirmed) %>%
  dplyr::filter(confirmed >= 25000) %>%
  dplyr::mutate(recover_rate = recovered / confirmed,
                death_rate = death / confirmed) %>% 
  dplyr::mutate(recover_rate = dplyr::if_else(is.na(recover_rate), 0, recover_rate),
                death_rate = dplyr::if_else(is.na(death_rate), 0, death_rate)) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(confirmed_normal = as.numeric(confirmed) / max(as.numeric(confirmed))) %>%
  plotly::plot_ly(y = ~ round(100 * recover_rate, 1),
                  x = ~ round(100 * death_rate, 1),
                  size = ~  log(confirmed),
                  sizes = c(5, 70),
                  type = 'scatter', mode = 'markers',
                  color = ~ country,
                  marker = list(sizemode = 'diameter' , opacity = 0.5),
                  hoverinfo = 'text',
                  text = ~paste("", country, 
                                " Confirmed Cases: ", confirmed,
                                " Recovery Rate: ", paste(round(100 * recover_rate, 1), "%", sep = ""),
                                " Death Rate: ",  paste(round(100 * death_rate, 1), "%", sep = ""))
                 ) %>%
  plotly::layout(yaxis = list(title = "Recovery Rate", ticksuffix = "%"),
                xaxis = list(title = "Death Rate", ticksuffix = "%", 
                             dtick = 1, 
                             tick0 = 0),
                hovermode = "compare")
  
```   
 

Column
------------------------------------- 

### Trajectory Plot - Major Countries 

```{r}

plotly::plot_ly(data = df_trajectory) %>%
  plotly::add_lines(x = ~ index,
                    y = ~ china,
                    line = list(color = "darkorange", width = 2),
                    name = "China") %>%
  plotly::add_lines(x = ~ index,
                    y = ~ india,
                    line = list(color = "navy", width = 2),
                    name = "India") %>%  
  plotly::add_lines(x = ~ index,
                    y = ~ pakistan,
                    line = list(color = "darkgreen", width = 2),
                    name = "Pakistan") %>%
  plotly::add_lines(x = ~ index,
                    y = ~ russia,
                    line = list(color = "dodgerblue1", width = 2),
                    name = "Russia") %>%  
  plotly::add_lines(x = ~ index,
                    y = ~ canada,
                    line = list(color = "firebrick1", width = 2),
                    name = "Canada") %>%   
  plotly::add_lines(x = ~ index,
                    y = ~ australia,
                    line = list(color = "gold", width = 2),
                    name = "Australia") %>%
  plotly::add_lines(x = ~ index,
                    y = ~ italy,
                    line = list(color = "hotpink", width = 2),
                    name = "Italy") %>%
  plotly::add_lines(x = ~ index,
                    y = ~ unitedstates,
                    line = list(color = "black", width = 2),
                    name = "United States") %>%
  plotly::add_lines(x = ~ index,
                    y = ~ unitedkingdom,
                    line = list(color = "coral4", width = 2),
                    name = "United Kingdom") %>%
  plotly::add_lines(x = ~ index,
                    y = ~ france,
                    line = list(color = "greenyellow", width = 2),
                    name = "France") %>%
  plotly::add_lines(x = ~ index,
                    y = ~ iran,
                    line = list(color = "dodgerblue4", width = 2),
                    name = "Iran") %>%
  plotly::add_lines(x = ~ index,
                    y = ~ sk,
                    line = list(color = "brown", width = 2),
                    name = "South Korea") %>%
  plotly::add_lines(x = ~ index,
                    y = ~ spain,
                    line = list(color = "blueviolet", width = 2),
                    name = "Spain") %>%
  plotly::layout(yaxis = list(title = "Cumulative Positive Cases",type = "log"),
                 xaxis = list(title = "Days since the total positive cases surpass 100"),
                 legend = list(x = 0.7, y = 0.3),
                 hovermode = "compare")
                 
```


### Treemap Plot 

```{r}

conf_df <- coronavirus %>% 
  filter(type == "confirmed") %>%
  group_by(country) %>%
  summarise(total_cases = sum(cases)) %>%
  arrange(-total_cases) %>%
  mutate(parents = "Confirmed") %>%
  ungroup() 
  
  plot_ly(data = conf_df,
          type = "treemap",
          values = ~ total_cases,
          labels = ~ country,
          parents =  ~ parents,
          domain = list(column = 0),
          name = "Confirmed",
          textinfo = "label + value + percent parent")
          
```

Key Data & Plots
=======================================================================


Row {data-width = 400}
-----------------------------------------------------------------------

### Cases Status Update for `r  max(coronavirus$date)`
    
```{r}

daily_summary <- coronavirus %>% 
  dplyr::filter(date == max(date)) %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total = sum(cases)) %>%
  tidyr::pivot_wider(names_from = type, values_from = total) %>%
  dplyr::arrange(-confirmed) %>%
  dplyr::select(country = country, confirmed, recovered, death)
  
  
  DT::datatable(data = daily_summary,
                rownames = FALSE,
                colnames = c("Country", "Confirmed", "Recovered", "Death"),
                options = list(pageLength = nrow(daily_summary), dom = 'tip'))
  
```


### Recovery and Death Rates by Country
    
```{r}

df_summary <-coronavirus %>% 
  dplyr::filter(country != "Others") %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total_cases = sum(cases)) %>%
  tidyr::pivot_wider(names_from = type, values_from = total_cases) %>%
  dplyr::arrange(- confirmed) %>%
  dplyr::filter(confirmed >= 25) %>%
  dplyr::select(country = country, confirmed, recovered, death) %>%
  dplyr::mutate(recover_rate = recovered / confirmed,
         death_rate = death / confirmed)  

df_summary %>%
  DT::datatable(rownames = FALSE,
            colnames = c("Country", "Confirmed", "Recovered", "Death", "Recovery Rate", "Death Rate"),
            options = list(pageLength = nrow(df_summary), dom = 'tip')) %>%
  DT::formatPercentage("recover_rate", 2) %>%
  DT::formatPercentage("death_rate", 2) 

```

    
Row {data-width = 400}
-----------------------------------------------------------------------


### Daily Cumulative Cases by Type
    
```{r}

plotly::plot_ly(data = df_daily,
                x = ~ date,
                y = ~ active_cumulative, 
                name = 'Active', 
                fillcolor = active_color,
                type = 'scatter',
                mode = 'none', 
                stackgroup = 'one') %>%
  plotly::add_trace(y = ~ recovered_cumulative,
                    name = "Recovered",
                    fillcolor = recovered_color) %>%
  plotly::add_trace(y = ~ death_cumulative,
                    name = "Death",
                    fillcolor = death_color) %>%
  plotly::layout(title = "",
                 yaxis = list(title = "Cumulative Number of Cases"),
                 xaxis = list(title = "Date"),
                 legend = list(x = 0.1, y = 0.9),
                 hovermode = "compare")
  

```


### New Cases - Top 15 Countries (`r  max(coronavirus$date)`)
    
```{r}

max_date <- max(coronavirus$date)

coronavirus %>% 
  dplyr::filter(type == "confirmed", date == max_date) %>%
  dplyr::group_by(country) %>%
  dplyr::summarise(total_cases = sum(cases)) %>%
  dplyr::arrange(-total_cases) %>%
  dplyr::mutate(country = factor(country, levels = country)) %>%
  dplyr::ungroup() %>%
  dplyr::top_n(n = 15, wt = total_cases) %>%
  plotly::plot_ly(x = ~ country,
                  y = ~ total_cases,
                  text = ~ total_cases,
                  textposition = 'auto',
                  type = "bar") %>%
  plotly::layout(yaxis = list(title = "Number of Cases"),
                 xaxis = list(title = "Country"),
                 margin =  list(
                   l = 10,
                   r = 10,
                   b = 10,
                   t = 10,
                   pad = 2
                 ))

```


Cumulative Results
=======================================================================


Column
------------------------------------- 

### Cumulative Confirmed Cases

```{r}

plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ confirmed_cumulative,
                    type = "bar",
                    name = "Active",
                    line = list(color = confirmed_color),
                    marker = list(color = confirmed_color)) %>%
  plotly::layout(yaxis = list(title = "Confirmed Cases (cumulative)"),
                 xaxis = list(title = ""))

```



### Cumulative Active Cases

```{r}

plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ active_cumulative,
                    type = "bar",
                    name = "Active",
                    line = list(color = active_color),
                    marker = list(color = active_color)) %>%
  plotly::layout(yaxis = list(title = "Active Cases (cumulative)"),
                 xaxis = list(title = ""))

```


Row
-------------------------------------------------------------------------

### Cumulative Recovered Cases

```{r}

plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ recovered_cumulative,
                    type = "bar",
                    name = "Recovered",
                    line = list(color = recovered_color),
                    marker = list(color = recovered_color)) %>%
  plotly::layout(yaxis = list(title = "Recovered Cases (cumulative)"),
                 xaxis = list(title = ""))

```



### Cumulative Death Cases

```{r}

plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ death_cumulative,
                    type = "bar",
                    name = "Death",
                    line = list(color = death_color),
                    marker = list(color = death_color)) %>%
  plotly::layout(yaxis = list(title = "Death Cases (cumulative)"),
                 xaxis = list(title = ""))

```


India
=======================================================================

Column 
-------------------------------------
    
### 
    
```{r, fig.height = 10}

df_India <- coronavirus %>% 
  filter(country == "India") %>%
  group_by(date, type) %>%
  summarise(total = sum(cases, na.rm = F)) %>%
  pivot_wider(names_from = type,
              values_from = total) %>%
  arrange(date) %>%
  ungroup()

df_India %>%
  datatable(rownames = F)

```
   
   
### Confirmed Cases in India

```{r, fig.width=10, fig.height=10}

plotly::plot_ly(data = df_India) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ confirmed,
                    type = "bar",
                    line = list(color = confirmed_color),
                    marker = list(color = confirmed_color)) %>%
  plotly::layout(yaxis = list(title = "Confirmed Cases"),
                 xaxis = list(title = ""))

```
   
Column 
-------------------------------------
   
### confirmed {.value-box}

```{r}

valueBox(value = paste(format(sum(df_india$confirmed), big.mark = ","), "", sep = " "),  
         caption = "Confirmed Cases in India",
         icon = "fas fa-user-md",
         color = confirmed_color)
```


### active {.value-box}

```{r}

valueBox(value = paste(format(sum(df_india$unrecovered, na.rm = T), big.mark = ","),
                       " (", round(100 * sum(df_india$unrecovered, na.rm = T) / sum(df_india$confirmed), 1),
                       "%)", sep = ""),
         caption = "Active Cases",
         icon = "fas fa-ambulance",
         color = active_color)
```

### recovered {.value-box}

```{r}

valueBox(value = paste(format(sum(df_india$recovered, na.rm = T), big.mark = ","),
                       " (", round(100 * sum(df_india$recovered, na.rm = T) / sum(df_india$confirmed), 1),
                       "%)", sep = ""),
         caption = "Recovered Cases",
         icon = "fas fa-heartbeat",
         color = recovered_color)
```

### death {.value-box}

```{r}

valueBox(value = paste(format(sum(df_india$death, na.rm = T), big.mark = ","), 
                       " (", round(100 * sum(df_india$death, na.rm = T) / sum(df_india$confirmed), 1), 
                       "%)", sep = ""),
         caption = "Death Cases", 
         icon = "fas fa-bed",
         color = death_color)

```
 

US
=======================================================================

Column 
-------------------------------------
    
### 
    
```{r, fig.height = 10}

df_US <- coronavirus %>% 
  filter(country == "US") %>%
  group_by(date, type) %>%
  summarise(total = sum(cases, na.rm = F)) %>%
  pivot_wider(names_from = type,
              values_from = total) %>%
  arrange(date) %>%
  ungroup()

df_US %>%
  datatable(rownames = F)

```
   
   
### Confirmed Cases in US

```{r, fig.width = 10, fig.height = 10}

plotly::plot_ly(data = df_US) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ confirmed,
                    type = "bar",
                    line = list(color = confirmed_color),
                    marker = list(color = confirmed_color)) %>%
  plotly::layout(yaxis = list(title = "Confirmed Cases"),
                 xaxis = list(title = ""))

```
   
Column 
-------------------------------------
   
### confirmed {.value-box}

```{r}

valueBox(value = paste(format(sum(df_us$confirmed), big.mark = ","), "", sep = " "), 
         caption = "Confirmed Cases in US",
         icon = "fas fa-user-md",
         color = confirmed_color)
```


### active {.value-box}

```{r}

valueBox(value = paste(format(sum(df_us$unrecovered, na.rm = T), big.mark = ","),
                       " (", round(100 * sum(df_us$unrecovered, na.rm = T) / sum(df_us$confirmed), 1),
                       "%)", sep = ""),
         caption = "Active Cases",
         icon = "fas fa-ambulance",
         color = active_color)
```

### recovered {.value-box}

```{r}

valueBox(value = paste(format(sum(df_us$recovered, na.rm = T), big.mark = ","),
                       " (", round(100 * sum(df_us$recovered, na.rm = T) / sum(df_us$confirmed), 1),
                       "%)", sep = ""),
         caption = "Recovered Cases",
         icon = "fas fa-heartbeat",
         color = recovered_color)
```

### death {.value-box}

```{r}

valueBox(value = paste(format(sum(df_us$death, na.rm = T), big.mark = ","), 
                       " (", round(100 * sum(df_us$death, na.rm = T) / sum(df_us$confirmed), 1), 
                       "%)", sep = ""),
         caption = "Death Cases", 
         icon = "fas fa-bed",
         color = death_color)

```
 


UK
=======================================================================

Column 
-------------------------------------
    
### 
    
```{r, fig.height = 10}

df_UK <- coronavirus %>% 
  filter(country == "United Kingdom") %>%
  group_by(date, type) %>%
  summarise(total = sum(cases, na.rm = F)) %>%
  pivot_wider(names_from = type,
              values_from = total) %>%
  arrange(date) %>%
  ungroup()

df_UK %>%
  datatable(rownames = F) 

```
   
   
### Confirmed Cases in UK

```{r, fig.width = 10, fig.height = 10}

plotly::plot_ly(data = df_UK) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ confirmed,
                    type = "bar",
                    line = list(color = confirmed_color),
                    marker = list(color = confirmed_color)) %>%
  plotly::layout(yaxis = list(title = "Confirmed Cases"),
                 xaxis = list(title = ""))
                 
```
   
Column 
-------------------------------------
   
### confirmed {.value-box}

```{r}

valueBox(value = paste(format(sum(df_uk$confirmed), big.mark = ","), "", sep = " "), 
         caption = "Confirmed Cases in UK",
         icon = "fas fa-user-md",
         color = confirmed_color)
```


### active {.value-box}

```{r}

valueBox(value = paste(format(sum(df_uk$unrecovered, na.rm = T), big.mark = ","),
                       " (", round(100 * sum(df_uk$unrecovered, na.rm = T) / sum(df_uk$confirmed), 1),
                       "%)", sep = ""),
         caption = "Active Cases",
         icon = "fas fa-ambulance",
         color = active_color)
```

### recovered {.value-box}

```{r}

valueBox(value = paste(format(sum(df_uk$recovered, na.rm = T), big.mark = ","),
                       " (", round(100 * sum(df_uk$recovered, na.rm = T) / sum(df_uk$confirmed), 1),
                       "%)", sep = ""),
         caption = "Recovered Cases",
         icon = "fas fa-heartbeat",
         color = recovered_color)
```

### death {.value-box}

```{r}

valueBox(value = paste(format(sum(df_uk$death, na.rm = T), big.mark = ","), 
                       " (", round(100 * sum(df_uk$death, na.rm = T) / sum(df_uk$confirmed), 1), 
                       "%)", sep = ""),
         caption = "Death Cases", 
         icon = "fas fa-bed",
         color = death_color)

```
 


About
=======================================================================

**The Coronavirus Dashboard**

This Coronavirus dashboard provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic. This dashboard is built with R using the [Rmarkdown](https://rmarkdown.rstudio.com/) using [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard/) framework and can easily reproduce by others.

**Data**

The input data for this dashboard is the [coronavirus](https://github.com/RamiKrispin/coronavirus) R package. The data and dashboard is refreshed on a daily bases. The raw data pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/RamiKrispin/coronavirus-csv)



**Packages**

* Dashboard interface - the [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard/) package. 
* Data manipulation - [tidyverse](https://dplyr.tidyverse.org/)
* Tables - the [DT](https://rstudio.github.io/DT/) package
* Visualisation - the [plotly](https://plot.ly/r/) package for the plots, [echarts4r](https://github.com/JohnCoene/echarts4r), [leafpop](https://github.com/r-spatial/leafpop) and [leaflet](https://rstudio.github.io/leaflet/) for the maps displayed

**Deployment and reproducibility**

The dashboard can be deployed to Rpubs or to Github docs. If you wish to deploy and/or modify the dashboard on your Github account, you can apply the following steps:

* Fork the dashboard [repository](https://github.com/mehtashubham/covid19_dashbaord), or
* Clone it and push it to your Github package
* Here some general guidance about deployment of flexdashboard on Github page - [link](https://github.com/pbatey/flexdashboard-example)

For any question or feedback, you can either open an [issue](https://github.com/mehtashubham/covid19_dashbaord/issues) or contact me on [LinkedIn](https://www.linkedin.com/in/mehta-shubham/).

**Contributions**

Special thanks John Ng and Zhan Liang Chan for guiding me through hosting this work on Github.io, and to all package developers who have contributed their bit in this development

**Dedication**

This dashboard has been created for usage by epidemiologists, data scientists and public in general. It is dedicated to all the health workers across the globe who are fighting this war from the front and impacting millions of lives with their great work. God bless them all. 

This too shall pass!